<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HotSpot JVM 新生代内存结构解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.6;
            color: #333;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .first-letter {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin-right: 0.2em;
            color: #4f46e5;
            font-weight: 700;
        }
        .code-block {
            background-color: #2d3748;
            color: #e2e8f0;
            border-radius: 0.375rem;
        }
        a {
            color: #4f46e5;
            transition: all 0.2s ease;
        }
        a:hover {
            color: #7c3aed;
            text-decoration: underline;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-5xl">
            <div class="text-center">
                <h1 class="text-4xl md:text-6xl font-bold mb-6 tracking-tight">HotSpot JVM 内存结构解析</h1>
                <p class="text-xl md:text-2xl font-light max-w-3xl mx-auto opacity-90">
                    深入探索新生代内存分配机制与垃圾回收优化策略
                </p>
                <div class="mt-8">
                    <span class="inline-block bg-white text-indigo-600 px-6 py-3 rounded-full font-medium shadow-md hover:shadow-lg transition-shadow duration-300">
                        <i class="fas fa-book-open mr-2"></i>探索更多
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12 md:py-16">
        <!-- Intro Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 h-2 w-12 bg-indigo-500 rounded-full"></div>
                <h2 class="ml-4 text-2xl md:text-3xl font-semibold">新生代内存分区</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="mb-4 text-gray-700"><span class="first-letter">在</span>HotSpot JVM中，新生代(Young Generation)的堆内存被精心划分为三个关键区域：Eden区和两个Survivor区(S0和S1)。这种分区设计是垃圾回收机制高效运行的基础架构。</p>
                    <p class="mb-4 text-gray-700">内存比例的默认配置体现了JVM设计者对对象生命周期模式的深刻理解。通过统计分析大多数应用场景，开发者发现新创建的对象具有极高的"夭折率"，这一洞察直接影响了内存区域的划分策略。</p>
                    <p class="text-gray-700">这种分区策略与复制算法(Copying Algorithm)完美配合，实现了高效的垃圾回收。Minor GC期间，存活对象在Eden和Survivor区间移动，最终达到一定年龄后晋升到老年代。</p>
                </div>
                <div class="relative">
                    <div class="bg-white p-6 rounded-xl shadow-lg card-hover">
                        <div class="mermaid">
                            pie showData
                                title 新生代内存分配比例
                                "Eden 区" : 80
                                "Survivor 0" : 10
                                "Survivor 1" : 10
                        </div>
                        <div class="mt-6 bg-indigo-50 p-4 rounded-lg border-l-4 border-indigo-500">
                            <p class="text-sm text-indigo-800"><i class="fas fa-info-circle mr-2"></i>图示展示了HotSpot JVM默认的新生代内存分配比例</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Detailed Explanation -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 h-2 w-12 bg-indigo-500 rounded-full"></div>
                <h2 class="ml-4 text-2xl md:text-3xl font-semibold">分区比例详解</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600">
                            <i class="fas fa-seedling text-xl"></i>
                        </div>
                        <h3 class="ml-3 text-xl font-semibold">Eden 区</h3>
                    </div>
                    <p class="text-gray-700">占据新生代80%的空间，是大多数新创建对象的初始分配区域。设计如此之大是因为统计分析表明，约98%的Java对象都是朝生夕死的。</p>
                    <div class="mt-4 px-4 py-2 bg-indigo-50 rounded-lg inline-block">
                        <p class="text-indigo-700 font-medium">80%新生代空间</p>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center text-purple-600">
                            <i class="fas fa-recycle text-xl"></i>
                        </div>
                        <h3 class="ml-3 text-xl font-semibold">Survivor 0</h3>
                    </div>
                    <p class="text-gray-700">与S1共同构成幸存区，各占10%空间。用于存储从Eden区存活下来的对象，经历多次GC后仍存活的对象将晋升到老年代。</p>
                    <div class="mt-4 px-4 py-2 bg-purple-50 rounded-lg inline-block">
                        <p class="text-purple-700 font-medium">10%新生代空间</p>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-pink-100 flex items-center justify-center text-pink-600">
                            <i class="fas fa-exchange-alt text-xl"></i>
                        </div>
                        <h3 class="ml-3 text-xl font-semibold">Survivor 1</h3>
                    </div>
                    <p class="text-gray-700">与S0功能相同，但在垃圾回收过程中互为"from"和"to"空间，确保始终有一个Survivor区是空的，用于接收存活对象。</p>
                    <div class="mt-4 px-4 py-2 bg-pink-50 rounded-lg inline-block">
                        <p class="text-pink-700 font-medium">10%新生代空间</p>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-xl overflow-hidden shadow-lg mb-8 card-hover">
                <div class="md:flex">
                    <div class="p-8 flex-1">
                        <h3 class="text-xl font-semibold mb-4">设计哲学解析</h3>
                        <p class="mb-4 text-gray-700">这种"大Eden小Survivor"的设计体现了空间与时间的精妙平衡：</p>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>大Eden区减少频繁Minor GC的需求，适应大多数对象短命的特点</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>小Survivor区确保只有真正长期存活的对象才能晋升到老年代</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>双Survivor设计实现了高效的复制算法，避免了内存碎片问题</span>
                            </li>
                        </ul>
                    </div>
                    <div class="bg-gray-50 p-8 flex-1 border-l border-gray-200">
                        <h3 class="text-xl font-semibold mb-4">对象生命周期图示</h3>
                        <div class="mermaid">
                            flowchart LR
                                A[新对象分配] --> B[Eden区]
                                B -->|Minor GC| C{对象存活?}
                                C -->|是| D[Survivor区]
                                C -->|否| E[被回收]
                                D -->|达到晋升年龄| F[老年代]
                                D -->|未达到年龄| D
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Configuration Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 h-2 w-12 bg-indigo-500 rounded-full"></div>
                <h2 class="ml-4 text-2xl md:text-3xl font-semibold">参数调优指南</h2>
            </div>
            
            <div class="bg-white rounded-xl overflow-hidden shadow-lg card-hover">
                <div class="p-8">
                    <h3 class="text-xl font-semibold mb-6">JVM内存参数调整</h3>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h4 class="text-lg font-medium mb-3 text-indigo-700">新生代与老年代比例</h4>
                            <p class="mb-4 text-gray-700">使用<code class="bg-gray-100 px-2 py-1 rounded">-XX:NewRatio</code>参数调整新生代与老年代的比例。例如，<code class="bg-gray-100 px-2 py-1 rounded">-XX:NewRatio=3</code>表示老年代是新生代的3倍。</p>
                            
                            <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-6">
                                <div class="flex">
                                    <div class="flex-shrink-0">
                                        <i class="fas fa-exclamation-triangle text-yellow-500"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-yellow-700">
                                            不建议将新生代设置过小，可能导致Minor GC频繁；也不建议过大，可能延长单次GC停顿时间。
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="text-lg font-medium mb-3 text-indigo-700">Eden与Survivor比例</h4>
                            <p class="mb-4 text-gray-700">使用<code class="bg-gray-100 px-2 py-1 rounded">-XX:SurvivorRatio</code>参数调整比例。<code class="bg-gray-100 px-2 py-1 rounded">-XX:SurvivorRatio=8</code>表示Eden是一个Survivor区的8倍。</p>
                            
                            <div class="bg-blue-50 border-l-4 border-blue-400 p-4">
                                <div class="flex">
                                    <div class="flex-shrink-0">
                                        <i class="fas fa-lightbulb text-blue-500"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-blue-700">
                                            对于存活率较高的应用，可以适当增大Survivor区；对于短命对象多的应用，可增大Eden区。
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8">
                        <h4 class="text-lg font-medium mb-3 text-indigo-700">配置示例</h4>
                        <div class="code-block p-4 rounded-lg">
                            <pre class="text-gray-300"><code># 设置堆大小为2G，新生代与老年代比例为1:3
# Eden与单个Survivor比例为6:1
java -Xms2g -Xmx2g \
     -XX:NewRatio=3 \
     -XX:SurvivorRatio=6 \
     -jar your-application.jar</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="text-center">
                <h3 class="text-xl font-medium text-white mb-2">技术小馆</h3>
                <p class="mb-6">深入探索技术原理与实践</p>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="inline-block px-6 py-2 bg-indigo-600 text-white rounded-full hover:bg-indigo-700 transition-colors duration-200">
                        访问语雀主页
                    </a>
                </div>
                <p class="mt-8 text-sm text-gray-500">© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: { 
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            pie: {
                useWidth: 400,
                showLegend: true,
                showDataValues: true
            }
        });
        
        // 添加简单的滚动动画
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>